package com.zdemo.hash1;

public class HashHandler {

	private Integer lastNum = 0;
	private Integer lastHashNum = 0;

	public Integer getLastNum() {
		return lastNum;
	}

	public void setLastNum(Integer lastNum) {
		this.lastNum = lastNum;
	}

	public Integer getLastHashNum() {
		return lastHashNum;
	}

	public void setLastHashNum(Integer lastHashNum) {
		this.lastHashNum = lastHashNum;
	}

	public Integer getHash(Integer num) {
		if (num.intValue() != this.lastHashNum.intValue()) {
			Integer hashNum = this.hash(num);
			this.sleep();
			this.lastNum = num;
			this.lastHashNum = hashNum;
		}
		return this.lastHashNum;

	}

	private Integer hash(Integer num) {
		Integer hashNum = num * 2;
		return hashNum;
	}

	private void sleep() {
		try {
			Thread.sleep((long) (Math.random() * 10 + 1));
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
